home *** CD-ROM | disk | FTP | other *** search
/ Joystick Magazine 1996 May / cd joy 71No13.iso / pc / demos / eurosoc / source / oldspt.cpp < prev    next >
C/C++ Source or Header  |  1996-01-31  |  9KB  |  411 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4.  
  5. #include "mallocx.h"
  6. #include "euro_def.h"
  7. #include "euro_var.h"
  8. #include "euro_dsk.h"
  9.  
  10. char    *script_buffer;
  11. FILE     *script_in;
  12. char    line[256];
  13. char    variable;
  14. int    variable_value;
  15.  
  16. void        Getvariable( char *buf );
  17. int         GetVariableValue( char *buf );
  18. void        ConvertLine(char *buf);
  19. void         GetTextString( char *buf);
  20. short         GetClubString( char *buf );
  21. char         GetFormationType( char *buf );
  22. char         GetTeamsCodeNumber( char *buf );
  23.  
  24. short    ImageXcount    =    0;
  25. short    ImageYcount    =    0;
  26. short    ImageWcount    =    0;
  27. short    ImageHcount    =    0;
  28. short    Pagecount    =    0;
  29. short    Stringcount    =    0;
  30. short    Clubcount    =    0;
  31. int    StringOffset    =    0;
  32. int    TempOffset    =    0;
  33. short    Formationcount    =    0;
  34. char    GroupDrawcount    =    0;
  35.  
  36. short    inst;
  37.  
  38. #define NO_INSTRUCTION         0
  39. #define IMAGE_xCOORD         1
  40. #define IMAGE_yCOORD         2
  41. #define IMAGE_WIDTH         3
  42. #define IMAGE_HEIGHT         4
  43. #define IMAGE_PAGE         5
  44. #define    TEXT_STRING         10
  45. #define    FORMATION_TYPE         100
  46. #define    GROUP_DRAW_TYPE         101
  47. #define    PLAYERS_CLUB_NAME    102
  48. #define    NULL_INSTRUCTION     255
  49.  
  50.  
  51. //********************************************************************************************************************************
  52.  
  53. char    process_script_file( char *file)
  54.     {
  55.  
  56.     script_buffer = (char *) mallocx(32768);
  57.  
  58.     if( script_buffer==NULL )
  59.         { 
  60.             printf("\nERROR: Unable to malloc script buffer...");
  61.             return(1);
  62.         }
  63.  
  64.  
  65.     else
  66.  
  67.         {
  68.             if( script_in = fopen ( file, "rt" ), script_in != NULL )
  69.             {
  70.                 while( ReadLine ( script_in, &line[0] ) >= 0 )
  71.                 {
  72.                     inst    =    0;
  73.                     ConvertLine(&line[0]);
  74.                     memset( line, 0, 256 );
  75.                 }
  76.                 fclose(script_in);
  77.             }
  78.             freex(script_buffer);
  79.         }
  80.     return(0);
  81.     }
  82.  
  83. //********************************************************************************************************************************
  84.  
  85. void    ConvertLine(char *buf)
  86. {
  87.     Getvariable(buf);
  88.  
  89.     while( variable != NO_INSTRUCTION )
  90.     {
  91.  
  92.         if ( variable == IMAGE_xCOORD )
  93.             { Image_Xcoords[ImageXcount] = GetVariableValue(buf); ImageXcount++;  }
  94.  
  95.         if ( variable == IMAGE_yCOORD )
  96.             { Image_Ycoords[ImageYcount] = GetVariableValue(buf); ImageYcount++; }
  97.  
  98.         if ( variable == IMAGE_WIDTH )
  99.             { Image_Widths[ImageWcount] = GetVariableValue(buf); ImageWcount++; }
  100.  
  101.         if ( variable == IMAGE_HEIGHT )
  102.             { Image_Heights[ImageHcount] = GetVariableValue(buf); ImageHcount++; }
  103.  
  104.         if ( variable == IMAGE_PAGE )
  105.             { Image_Pages[Pagecount] = GetVariableValue(buf); Pagecount++; }
  106.  
  107.         if ( variable == TEXT_STRING )
  108.             { Text[Stringcount] = TextStrings+StringOffset; GetTextString(buf); Stringcount++; }
  109.  
  110.         if ( variable == FORMATION_TYPE )
  111.             { FormationInfo[Formationcount] = GetFormationType(buf); Formationcount++; }
  112.  
  113.         if ( variable == GROUP_DRAW_TYPE )
  114.             { GroupDrawInfo[GroupDrawcount] = GetTeamsCodeNumber(buf); GroupDrawcount++; }
  115.  
  116.         if ( variable == PLAYERS_CLUB_NAME )
  117.             { 
  118.                 TempOffset      = StringOffset;
  119.                 Text[Stringcount] = TextStrings+StringOffset; 
  120.  
  121.                 short    Clubnum   = GetClubString(buf);
  122.                 
  123.                 if ( Clubnum == NOT_FOUND )
  124.                 {
  125.                     Clubs[Clubcount] = Stringcount;
  126.                     Stringcount++;                      
  127.                 } 
  128.  
  129.                 else
  130.  
  131.                 {
  132.                     Clubs[Clubcount] = Clubnum;
  133.                     StringOffset     = TempOffset;
  134.                 }
  135.                 
  136.                 Clubcount++; 
  137.             }
  138.  
  139.  
  140.         Getvariable(buf);
  141.     }    
  142. }
  143.  
  144. //********************************************************************************************************************************
  145.  
  146. int     GetVariableValue( char *buf )    //, int inst )
  147.     {
  148.         int      val, offset;
  149.         char     number[10];
  150.         offset    =    0;            
  151.         val    =    0;            
  152.         
  153.         while ( buf[inst] > ('0'-1) && buf[inst] < ('9'+1) )
  154.         {
  155.             number[offset]    =    buf[inst];
  156.             inst++;
  157.             offset++;
  158.         }    
  159.             number[offset]    =    0;
  160.  
  161.         val         =     atoi(number);
  162.         return    ( val );
  163.     }
  164.  
  165. //********************************************************************************************************************************
  166.  
  167. char     GetFormationType( char *buf )
  168.     {
  169.         int      val, offset;
  170.         char    form    =    0;
  171.         char     number[10];
  172.         offset    =    0;            
  173.         val    =    0;            
  174.         
  175.         if (buf[inst]==' ')
  176.             inst++;
  177.                 
  178.         while ( buf[inst] > ('0'-1) && buf[inst] < ('9'+1) )
  179.         {
  180.             number[offset]    =    buf[inst];
  181.             inst++;
  182.             if (buf[inst]=='-')
  183.                 inst++;
  184.             offset++;
  185.         }    
  186.             number[offset]    =    0;
  187.             
  188.         val         =     atoi(number);
  189.  
  190.         switch (val)
  191.         {
  192.             case(316):
  193.                 form    =    0;
  194.                 break;
  195.             case(406):
  196.                 form    =    1;
  197.                 break;
  198.             case(415):
  199.                 form    =    2;
  200.                 break;
  201.             case(424):
  202.                 form    =    3;
  203.                 break;
  204.             case(433):
  205.                 form    =    4;
  206.                 break;
  207.             case(442):
  208.                 form    =    5;
  209.                 break;
  210.             case(514):
  211.                 form    =    6;
  212.                 break;
  213.             case(523):
  214.                 form    =    7;
  215.                 break;
  216.             case(532):
  217.                 form    =    8;
  218.                 break;
  219.             case(631):
  220.                 form    =    9;
  221.                 break;
  222.  
  223.         }
  224.  
  225.         return    ( form );
  226.     }
  227.  
  228. //********************************************************************************************************************************
  229.  
  230. char     GetTeamsCodeNumber( char *buf )
  231.     {
  232.         char      val;
  233.         val    =    0;            
  234.         
  235.         if (buf[inst]==' ')
  236.             inst++;
  237.                 
  238.         while ( buf[inst] > ('0'-1) && buf[inst] < ('9'+1) )
  239.         {
  240.             if ( buf[inst+1] < 'a' )
  241.                 val    =     ((buf[inst+1]-'A')*4);
  242.             else
  243.                 val    =     ((buf[inst+1]-'a')*4);
  244.  
  245.             val+=    (buf[inst]-'1');
  246.             inst+=    2;
  247.         }    
  248.  
  249.         printf    ("val    =    %d\n", val);
  250.  
  251.     return    ( val );
  252.     }
  253.  
  254. //********************************************************************************************************************************
  255.  
  256. void     GetTextString( char *buf )    //, int inst )
  257.     {
  258.         char    CRflag    =    2;
  259.  
  260.         while ( CRflag!=0 )
  261.         {
  262.              if ( buf[inst] == '"' )
  263.                 CRflag--;
  264.              if ( buf[inst] > 31 && buf[inst] != '/' && buf[inst]!='"' && CRflag==1)
  265.                 {
  266.                 TextStrings[StringOffset] = buf[inst];
  267.                 StringOffset++;
  268.                 }
  269.              if ( buf[inst+1] > 31 && buf[inst] == '/' && CRflag==1)
  270.                 {
  271.                 TextStrings[StringOffset] = buf[inst+1];
  272.                 StringOffset++;
  273.                 inst++;
  274.                 }                    
  275.              if ( (buf[inst] < 31 && CRflag==1) || StringOffset>16383 )
  276.                 CRflag = 0;
  277.         inst++;
  278.         }
  279.  
  280.         TextStrings[StringOffset] = 0;
  281.         StringOffset++;
  282.     }
  283.  
  284. //********************************************************************************************************************************
  285.  
  286. short     GetClubString( char *buf )    
  287.     {
  288.  
  289.  
  290.  
  291.     // ****** GET PLAYERS CLUB ******        
  292.  
  293.  
  294.  
  295.         char    PlayerClub[25];
  296.         char    string[25];
  297.         int    ClubOffset     =     0;
  298.         char    CRflag        =    2;
  299.         int    CompareOffset    =    0;
  300.         short    ClubFound    =    NOT_FOUND;
  301.         CRflag            =    1;
  302.         
  303.  
  304.         while ( CRflag!=0 )
  305.         {
  306.              if ( buf[inst] == '"' )
  307.                 CRflag--;
  308.  
  309.              if ( buf[inst] > 31 && buf[inst]!='"' && CRflag==1)
  310.                 {
  311.                     PlayerClub[ClubOffset] = buf[inst];
  312.                     ClubOffset++;
  313.                 }
  314.  
  315.              if ( buf[inst] < 31 && CRflag==1 )
  316.                     CRflag = 0;
  317.  
  318.              inst++;
  319.         }
  320.  
  321.         PlayerClub[ClubOffset] = 0;
  322.         ClubOffset++;
  323.  
  324.  
  325.  
  326.     // ****** SEARCH THROUGH STRING LIST FOR REPEAT OF CLUB NAME ******
  327.  
  328.  
  329.  
  330.         for ( short s=0; s < Stringcount ; s++ )             
  331.         {
  332.             int CopyOffset    =    0;
  333.  
  334.             while ( CRflag!=0 )
  335.             {
  336.                 if ( TextStrings[CompareOffset] == 0 )
  337.                 {
  338.                     string[CopyOffset] = 0;
  339.                      CRflag    =    0;
  340.                 }
  341.  
  342.                 else
  343.                 {   
  344.                     string[CopyOffset] = TextStrings[CompareOffset];
  345.                 }
  346.  
  347.                 CopyOffset++;
  348.                 CompareOffset++;
  349.             }
  350.             
  351.             if ( strcmpi( PlayerClub, string ) == 0 )
  352.                 {
  353.                     ClubFound    =    s;        
  354. //                    break;
  355.                 }                
  356.         }
  357.  
  358.  
  359.     // ****** THROW CLUB STRING INTO TEXT LIST ******
  360.  
  361.             
  362.             if ( ClubFound == NOT_FOUND )
  363.             {
  364.                 GetTextString( PlayerClub );
  365.             }        
  366.         
  367.         return(ClubFound);
  368.     }
  369.  
  370. //********************************************************************************************************************************
  371.  
  372. void     Getvariable( char *buf )      
  373.     {
  374.         variable = NO_INSTRUCTION;
  375.                     
  376.         while ( buf[inst] != 0 && variable == NO_INSTRUCTION )
  377.         {
  378.  
  379.             if ( buf[inst+1] == ':')
  380.             {
  381.                 if ( buf[inst] == 'x' )
  382.                      {variable = IMAGE_xCOORD; inst+=2;} 
  383.                 if ( buf[inst] == 'y' )
  384.                      {variable = IMAGE_yCOORD; inst+=2;}
  385.                 if ( buf[inst] == 'w' )
  386.                      {variable = IMAGE_WIDTH; inst+=2;}
  387.                 if ( buf[inst] == 'h' )
  388.                      {variable = IMAGE_HEIGHT; inst+=2;}
  389.                 if ( buf[inst] == 'p' )
  390.                      {variable = IMAGE_PAGE; inst+=2;}
  391.                 if ( buf[inst] == 't' )
  392.                      {variable = TEXT_STRING; inst+=2;}
  393.             }
  394.  
  395.             if ( buf[inst+4] == ':')
  396.             {
  397.                 if ( buf[inst] == 'f' && buf[inst+1] == 'o' && buf[inst+2] == 'r' && buf[inst+3] == 'm' )
  398.                      {variable = FORMATION_TYPE; inst+=5;}
  399.                 if ( buf[inst] == 'd' && buf[inst+1] == 'r' && buf[inst+2] == 'a' && buf[inst+3] == 'w' )
  400.                      {variable = GROUP_DRAW_TYPE; inst+=5;}
  401.                 if ( buf[inst] == 'c' && buf[inst+1] == 'l' && buf[inst+2] == 'u' && buf[inst+3] == 'b' )
  402.                      {variable = PLAYERS_CLUB_NAME; inst+=5;}
  403.             }
  404.  
  405.             if (variable == NO_INSTRUCTION)
  406.                 inst++;
  407.         }    
  408.     }
  409.  
  410. //********************************************************************************************************************************
  411.